<include file="Public:header" />
<include file="Public:leftside" />
<link rel="stylesheet" type="text/css" href="/Store/css/order/order.css" />
<link rel="stylesheet" type="text/css" href="/Store/css/WdatePicker/skin/WdatePicker.css" />
<script src="/Store/css/WdatePicker/WdatePicker.js" type="text/javascript" charset="utf-8"></script>
<div class="main-content" id="mainContent">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
			<a href="/">首页</a>
			</li>
			<li>
				<a href="{:U('Order/order_list')}">订单列表</a>
			</li>
		</ul>
	</div>

	<div class="tabmenu">
		<ul class="tab pngFix">
			
			<li class="<php>if($_GET["status"]==null&&$_GET["refund_state"]!=1){echo "active";}</php>">
				<a href="{:U('Order/order_list')}">全部</a>
			</li>
			
			<li class="daohang_no <eq name='_GET["status"]' value="10">active</eq>">
				<a href="{:U('Order/order_list',array('status'=>10))}">待付款</a>
			</li>
			<li class="daohang_no <eq name='_GET["status"]' value="20">active</eq>">
				<a href="{:U('Order/order_list',array('status'=>20))}">待发货</a>
			</li>
			<li class="daohang_no <eq name='_GET["status"]' value="30">active</eq>">
				<a href="{:U('Order/order_list',array('status'=>30))}">已发货</a>
			</li>
			<li class="daohang_no <eq name='_GET["status"]' value="40">active</eq>">
				<a href="{:U('Order/order_list',array('status'=>40))}">已收货</a>
			</li>
			
			<li class="daohang_no <eq name='_GET["status"]' value="0">active</eq>">
				<a href="{:U('Order/order_list',array('status'=>0))}">已关闭</a>
			</li>
			<li class="daohang_no <eq name='_GET["refund_state"]' value="1">active</eq>">
				<a href="{:U('Order/order_list',array('refund_state'=>1))}">退款中</a>
			</li>
		</ul>

	</div>
	<hr class="tabmenu_hr" style="border:1px solid #00C0FF;margin:0 0px 10px 20px;background: #fff;	">

	<div class="main">

		<form id="mallSearch" action="{:U('Order/order_list',array('status'=>$_GET['status']))}" method="get" class="form-inline">
		<table class="mytable">
			<tbody>
				<tr>
					<th style="line-height:33px;">
						下单时间：<input type="text" name="startDate" value="{$_GET['startDate']}" class="input-medium" placeholder="请选择开始日期" onclick="WdatePicker()"> &nbsp;-&nbsp;
						<input type="text" name="endDate" value="{$_GET['endDate']}" placeholder="请选择结束日期" class="input-medium" onclick="WdatePicker()"> 收货人姓名：
						<input name="userName" class="input-small" type="text" value="{$_GET['userName']}"> 订单编号：
						<input name="orderNo" class="input-medium" type="text" value="{$_GET['orderNo']}" style="display:inline-block;margin-right: 20px;">
					</th>
				</tr>
			</tbody>
		</table>
		<table class="mytable">
			<tbody>
				<tr>
					<th>
						收货人手机号：<input name="receiverMobile" class="input-small" type="text" value="{$_GET['receiverMobile']}"> 支付方式：
						<select name="payment_type">
							<option value="">全部</option>
							<option value="微信" <eq name="_GET['payment_type']" value="微信">selected</eq>>微信</option> 
							<option value="支付宝" <eq name="_GET['payment_type']" value="支付宝">selected</eq>>支付宝</option>
						</select>
						<input type="submit"  value="搜索"  class="btn btn btn-info btn-sm">
						<a href="{:U('Order/order_list',array('status'=>$_GET['status']))}" class="btn btn-sm btn-default">清空</a>
					</th>
				</tr>
			</tbody>
		</table>
		</form>
		<div class="style0list">
			<table>
				<colgroup>
					<col width="5%">
					<col width="35%">
					<col width="12%">
					<col width="10%">
					<col width="12%">
					<col width="10%">
					<col width="10%">
					<col width="10%">
				</colgroup>
				<thead>
					<tr align="center">
						<th><label style="margin-left: 5px;"> <input type="checkbox" onclick="CheckAll(this)"></label></th>
						<th>商品信息</th>
						<th style="text-align: center;">商品清单</th>
						<th style="text-align: center;">买家</th>
						<th style="text-align: center;">收货信息</th>
						<th style="text-align: center;">订单金额</th>

						<th style="text-align: center;">交易状态</th>
						<th style="text-align: center;border-right: 1px solid #E3E3E3;">操作</th>
					</tr>
				</thead>
				<tbody>
					<foreach name="order_list" item="vo">

						<tr class="title-tr">
							<td colspan="9"><input id="1502955487848" type="checkbox" onclick="CheckThis()" value="5" name="sub"><span>订单编号：{$vo['order_sn']}</span><span>下单时间：{:date('Y-m-d H:i:s',$vo['add_time'])}</span></td>
						</tr>
						<php>$shop_list=get_order_shop($vo['order_id']);$count=count($shop_list);</php>
						<foreach name="shop_list" item="v" key="k">
							<tr>
								<td colspan="2" style="border-right:0;">
									<div class="product-img"><img src="{$v['goods_image']}" style="height: 100px;"></div>
									<div class="product-infor">
										<a href="{:U('shop/index',array('id'=>$v['goods_id']))}" target="_blank">{$v['goods_name']}</a>
										<p class="specification"><span><notempty name="v['goods_sku_spec']">规格：{$v['goods_sku_spec']}</notempty>
										<notempty name="v['goods_sku_style']">颜色：{$v['goods_sku_style']}</notempty></span></p>
									</div>

								</td>

								<td style="border-right:1px solid #E3E3E3;text-align:center;">
									<div class="cell" style="display: inline-block;"><span>{$v['goods_price']}元</span></div>
									<div class="cell">{$v['goods_num']}件</div>
								</td>
								<php>$userinfo=get_user($vo['buyer_id']);</php>
								<eq name="k" value="0">

									<td rowspan="{$count}" style="text-align:center">
										<div class="cell">{$userinfo['username']}<br>
											<eq name="vo.order_from" value="1">pc端</eq>
											<eq name="vo.order_from" value="2">手机端</eq>
										</div>
									</td>
									<php>
										$ProvinceInfo=getProvinceInfo($vo['buyer_province']); $CityInfo=getCityInfo($vo['buyer_city']); $DistrictInfo=getDistrictInfo($vo['buyer_district']);
									</php>
									<td rowspan="{$count}" style="text-align:center">
										<div style="text-align:left;"><span class="expressfee">{$vo['buyer_name']}</span><br><span class="expressfee">{$vo['buyer_mobile']}</span><br><span class="expressfee">{$ProvinceInfo['province_name']}{$CityInfo['city_name']}{$DistrictInfo['district_name']}{$vo['buyer_address']}</span></div>
									</td>
									<td rowspan="{$count}" style="text-align:center">
										<div class="cell">

											<b class="netprice" style="color:#666;">{$vo['order_amount']}</b><br>
											<span class="expressfee">(含快递:{$vo['shipping_fee']})</span><br>
											<span class="expressfee">{$vo['payment_code']}</span>
										</div>
									</td>
									<php>
										if($vo['tuanselect']==1){
											if($vo['tuan_is_first_id']==0){
												$num=get_tuan($vo['order_id']);
											}else{
												$num=get_tuan($vo['tuan_is_first_id']);
											}
											
										}
									</php>
									<td rowspan="{$count}">
										<div class="business-status" style="text-align:center">
											<eq name="vo['refund_state']" value="0">
												<eq name="vo['order_state']" value="0">
													已取消
												</eq>
												<eq name="vo['order_state']" value="10">
													等待买家付款
												</eq>
												<eq name="vo['order_state']" value="20">
													<php>if($vo['tuanselect']==1&&$vo['tuan_is_success']==0){</php>
														拼团中
													<php>}elseif($vo['tuanselect']==1&&$vo['tuan_is_success']==1){</php>
														拼团成功<br/>等待卖家发货
													<php>}else{</php>
														等待卖家发货
													<php>}</php>
													
												</eq>
												<eq name="vo['order_state']" value="30">
													等待买家收货
												</eq>
												<eq name="vo['order_state']" value="40">
													待评价
												</eq>
											</eq>
											<gt name="vo['refund_state']" value="0">
												<eq name="vo['refund_state']" value="1">
													退款,待审核
												</eq>
												<eq name="vo['refund_state']" value="2">
													已同意
													<php>if($vo['refund_type']==2&&$vo['refund_shipping_code']==null){</php>
														待买家发货	
													<php>}</php>
													<notempty name="vo['refund_shipping_code']">
													<br>买家已发货
													</notempty>
													
												</eq>
												<eq name="vo['refund_state']" value="3">
													已拒绝退款
												</eq>
												
												<eq name="vo['refund_state']" value="4">
													等待财务待打款
												</eq>
												<eq name="vo['refund_state']" value="5">
													退款完成
												</eq>
												<eq name="vo['refund_type']" value="1"><br/>(我要退款，但不退货)</eq>
												<eq name="vo['refund_type']" value="2"><br/>(我要退款，退货)</eq>
											</gt>
										</div>
									</td>
									<td rowspan="{$count}" style="text-align:center;">
										<a class="btn btn-info shipping btnstyle" style="background:#27a9e3!important;" href="{:U('order/order_info',array('id'=>$vo['order_id']))}">详情</a>
										<eq name="vo['order_state']" value="10">
											<eq name="vo['refund_state']" value="0">
												<a class="btn btn-info shipping btnstyle" style="background:green!important;" onclick="modifyPrice({$vo['order_id']},{$vo['order_amount']},{$vo['order_sn']})">修改价格</a>
											</eq>
										</eq>
										<eq name="vo['order_state']" value="20">
											<eq name="vo['refund_state']" value="0">
											<php>if($vo['tuanselect']==1&&$vo['tuan_is_success']==0){</php>
												<a class="btn btn-info shipping btnstyle" style="background:green!important;" href="javascript:;">拼团中</a>
											<php>}elseif($vo['tuanselect']==1&&$vo['tuan_is_success']==1){</php>
												<a class="btn btn-info shipping btnstyle" style="background:green!important;" href="javascript:operation('delivery',{$vo['order_id']})">发货</a>
											<php>}else{</php>
												<a class="btn btn-info shipping btnstyle" style="background:green!important;" href="javascript:operation('delivery',{$vo['order_id']})">发货</a>
											<php>}</php>
											</eq>
										</eq>
										<neq name="vo['refund_state']" value="0">
											<eq name="vo['refund_state']" value="1">
												<a class="btn btn-info shipping btnstyle" style="background:green!important;" href="javascript:back_return({$vo['order_id']},2)">同意</a>
												<a class="btn btn-info shipping btnstyle" style="border: 1px solid red;background:red!important;" href="javascript:back_return({$vo['order_id']},3)">拒绝</a>
											</eq>
										</neq>
									</td>
								</eq>

							</tr>

						</foreach>
					</foreach>

				</tbody>
			</table>
		</div>
		<style type="text/css">
			#pagination{
				    padding: 23px;
			}
			#pagination div{
				   float:left;
			}
			#pagination a {
				padding: 3px 9px;
				border: 1px solid #988f8f;
				margin-right: 3px;
			}
			
			#pagination span {
				padding: 3px 9px;
				border: 1px solid #988f8f;
				margin-right: 3px;
				background: red;
				color: #fff;
			}
			.page div span, .page div a{border-radius: 2px;}
		</style>
		<div id="pagination" class="page page-wrap fr">
			<div>
				{$page} <div style="line-height: 21px;">&nbsp;共{$counts}条记录</div>
			</div>
		</div>

	</div>
</div>

<div class="modal fade" id="Delivery" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display:none;">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" id="myModalLabel">商品发货</h4>
			</div>
			<div class="modal-body">

				<div style="clear:both;"></div>
				<div class="form-group" id="express_input" style="height: 36px;">
					<select class="form-control input-lg" id="divlogistics_express_company" style="margin-bottom:5px;margin-right:15px;float:left;"></select>
					<div class="col-lg-2"><input type="text" id="divlogistics_express_no" class="form-control" placeholder="请填写快递单号" style="height: 32px;width: 270px;"></div>
				</div>
				<div id="receiver_info"></div>
			</div>

			<div class="modal-footer">
				<input type="hidden" id="delivery_order_id" value="" />
				<button type="button" class="btn btn-info" onclick="orderDeliverySubmit()" style="display:inline-block;background: #00C0FF!important;">提交更改</button>
				<button type="button" class="btn btn-info" style="display:inline-block;background: red!important;" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="modifyPrice" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display:none;width:35%;">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title" >订单价格修改</h4>
			</div>
			<div class="modal-body">

				<div class="modal-infp-style">
					<table>
						<tbody>
						<tr style="height:40px;">
							<td>订单编号:  </td>
							<td colspan="3" id="order_sn"></td>
						</tr>
						<tr>
							<td>价格:  </td>
							<td colspan="3"><input type="text" id="price" class="price"></td>
						</tr>
						</tbody>
					</table>
				</div>
			</div>

			<div class="modal-footer">
				<input type="hidden" id="order_id" value="" />
				<button type="button" class="btn btn-info" onclick="price_modify()" style="display:inline-block;background: #00C0FF!important;">提交更改</button>
				<button type="button" class="btn btn-info" style="display:inline-block;background: red!important;" data-dismiss="modal">关闭</button>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	function del() {
		var msg = "您真的确定要删除吗？\n\n请确认！";
		if(confirm(msg) == true) {
			return true;
		} else {
			return false;
		}
	}
	/*****订单相关操作函数开始*****/
	function operation(operation_type, order_id) {
		//		if(operation_type == 'pay'){
		//			orderOffLinePay(order_id);//线下支付
		//		}else if(operation_type == 'complete'){
		//			orderComplete(order_id);//交易完成
		//		}else else if(operation_type == 'close'){
		//			orderClose(order_id);//交易关闭
		//		}else if(operation_type == 'adjust_price'){
		//			modifyPrice(order_id);//修改价格
		//		}else if(operation_type == 'pickup'){
		//			pickuporder(order_id);//提货
		//		}else if(operation_type == 'seller_memo'){
		//			orderSellerMemo(order_id);//备注
		//		}else if(operation_type == 'logistics'){
		//			//查看物流
		//			location.href = ADMINMAIN+'/order/orderdetail?order_id='+order_id;
		//		}
		//		
		if(operation_type == 'delivery') {
			orderDelivery(order_id); //发货
		}
	}

    function modifyPrice(order_id,price,orderNo) {
        $("#modifyPrice").modal('show');
        $("#order_id").val(order_id);
        $("#order_sn").text(orderNo);
        $("#price").val(price);
    }
    function price_modify() {
        var order_id = $("#order_id").val();
        var price = $("#price").val();
        if(price<0) {
            layer.msg('价格不能小于零！')
            return false;
        }
        $.ajax({
            type: "post",
            url: "{:U('Order/edit_price')}",
            data: {
                "order_id": order_id,
                "price": price,
            },
            success: function(data) {
                json= JSON.parse(data);
                if(json.status == 0) {
                    layer.msg('无数据更新！')
                }
                if(json.status == 1) {
                    layer.msg('修改成功！');
                    setTimeout("location.reload()",1000);
                }
            }
        });
    }
	function back_return(order_id,type){
		if(!confirm('提示，是否确认该操作？')){
			return;
		}
		$.ajax({
			type: "get",
			url: "{:U('order/back_retun')}",
			data: {
				'order_id': order_id,
				'type': type
			},
			success: function(data) {
				if(data.status==1){
					layer.msg(data.info);
					setTimeout("window.location.reload()", 1000)
				}else {
					layer.msg(data.info);
				}
			}
		});
	}
	function orderDelivery(order_id) {
		$("#Delivery").modal('show');
		$("#divlogistics_express_company option").remove();
		$("#Delivery .modal-body table tbody tr").remove();
		$.ajax({
			type: "post",
			url: "{:U('order/get_delivery')}",
			data: {
				'order_id': order_id
			},
			success: function(data) {
				console.log(data)
				$("#delivery_order_id").val(order_id);
				var receiver_info = '收货信息' + data['order_info']['address'];
				$("#receiver_info").html(receiver_info);
				var co_html = '';
				co_html += '<option value="0" >请选择物流公司</option>';
				for(var i = 0; i < data['express_company_list'].length; i++) {

					if(data['express_company_list'][i]['is_enabled'] == '1') {
						co_html += '<option value="' + data["express_company_list"][i]["express_no"] + '">' + data["express_company_list"][i]["company_name"] + '</option>';
					}
				}
				$("#divlogistics_express_company").append(co_html);
				$("#divlogistics_express_company").val(0);

			}
		});
	}

	function orderDeliverySubmit() {
		var order_id = $("#delivery_order_id").val();
		var order_goods_id_array = '';

		var express_name = $("#divlogistics_express_company").find("option:selected").text();

		var express_company_id = $("#divlogistics_express_company").val();
		var express_no = $("#divlogistics_express_no").val();

		if(express_company_id == "0") {
			layer.msg('必须选择物流公司');

			return false;
		}
		if(express_no == "") {
			layer.msg('必须填写快递单号');

			return false;
		}

		$.ajax({
			type: "post",
			url: "{:U('order/put_delivery')}",
			data: {
				'order_id': order_id,
				"express_name": express_name,
				"express_company_id": express_company_id,
				"express_no": express_no
			},
			success: function(data) {
				$("#Delivery").modal('hide');
				if(data['code'] > 0) {
					layer.msg(data["message"]);
					setTimeout("window.location.reload()", 1000)
				} else {
					layer.msg(data["message"]);
				}
			}
		});
	}
</script>

<include file="Public:footer" />